package com.example.demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by Administrator on 2017/6/30.
 */
@Controller
@RequestMapping("/user")
public class UserController {


    @RequestMapping(value = "/login",method = RequestMethod.GET)
    public ModelAndView loginPage(HttpServletRequest request){
        return new ModelAndView("login");
    }

    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public ModelAndView postLogin(HttpServletRequest request,String username,String password){
        System.out.println(username);
        System.out.println(password);
        if("admin".equals(username) && "123456".equals(password)){
            request.getSession().setAttribute("username",username);
            return new ModelAndView("info");
        }else{
            return new ModelAndView("login");
        }
    }

    @RequestMapping(value = "/info",method = RequestMethod.GET)
    public ModelAndView info(HttpServletRequest request){

        String username  = (String )request.getSession().getAttribute("username");
        return new ModelAndView("info").addObject("username",username);
    }

    @RequestMapping(value = "/info",method = RequestMethod.POST)
    public ModelAndView postInfo(HttpServletRequest request){
        return new ModelAndView("");
    }
}
